#pragma once

#include "QtAnimStruct.h"

#include <QtGui/QGraphicsRectItem>
#include <QtGui/QPixmap>
#include <QtCore/QTimeLine>

class QtGraphicsStateScene;
class QtVariantProperty;
class QtButtonPropertyBrowser;
class QtTreePropertyBrowser;
class QtGroupBoxPropertyBrowser;
class QtVariantPropertyManager;
class QtProperty;
class QtGraphicsLinkItem;


class QtAnimGraphicsItem : public QObject, public QGraphicsRectItem
{
	Q_OBJECT
		Q_PROPERTY(qreal scale READ scale WRITE setScale)
		Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
	QtAnimGraphicsItem(QGraphicsItem* parent = 0);
	virtual ~QtAnimGraphicsItem(void);

	void setPixmap(const QPixmap& pixmap);
	virtual void createPropertyWidget();
	QtGroupBoxPropertyBrowser* getPropertyWidget() const { return mPropertyWidget; }
	QtGraphicsStateScene* getStateScene() const { return mStateScene; }

	virtual QRectF	boundingRect () const;
	virtual void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );

	void createAnim(QtGraphicsLinkItem* pLinkItem);
	const QPointF& getTransTranslate() const;
	const QVector3D& getTransRotate() const;
	const QPointF& getTransScale() const;

	friend QDataStream & operator << (QDataStream &dataStream, QtAnimGraphicsItem &itemBase);
	friend QDataStream & operator >> (QDataStream &dataStream, QtAnimGraphicsItem &itemBase);
	virtual void save(QDataStream &dataStream);
	virtual void load(QDataStream &dataStream);

protected:
	virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
	virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent * event );

	QVariant itemChange(GraphicsItemChange change, const QVariant &value);
signals:
	void propertyChanged(QtProperty *, const QVariant &);
	void stateChanged(const QPointF&, const QVector3D&, const QPointF&);
public slots:
	void setProperty(QtProperty *prop, const QVariant &value);
	void updateAnimStep(qreal timeStep);
	void playAnim();
	void stateSelected(const QPointF& trans, const QVector3D& rot, const QPointF& scale);
protected:
	QPixmap mPixmap;

	QVector<QtAnimStruct> mAnimList;

	QtGraphicsStateScene* mStateScene;

	QtGroupBoxPropertyBrowser* mPropertyWidget;
	QtVariantPropertyManager* mVariantManager;
	QtVariantProperty* mPixmapFile;
	/*QtVariantProperty* mPosProperty;
	QtVariantProperty* mScaleProperty;*/
	QtVariantProperty* mTransTranProp;
	QtVariantProperty* mTransRotProp;
	QtVariantProperty* mTransScaleProp;
};
